﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;
using AdaptiveHelpDesk;

namespace Novice
{
    [WebService(Namespace = "http://soaiui.nmmu.ac.za/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]    
    public class CustomerDetails : System.Web.Services.WebService
    {
        //Hashtable and arraylist used to load search results
        Hashtable ht = new Hashtable();
        ArrayList values = new ArrayList();

        //initialise stored procedures
        StoredProcedures sp = new StoredProcedures();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="SearchBy"></param>
        /// <param name="searchResult">the is the search value. It is named after the 
        /// search result element on which this service is a dependent.
        /// </param>
        /// <returns></returns>
        [WebMethod]
        public user ViewSelectedCustomer(String SearchBy, String searchResults)
        {
            user u = new user();
            ht = sp.getCustomer("UserID", searchResults);

            if (ht.Count != 0)
            {
                foreach (DictionaryEntry de in ht)
                {
                    values = (ArrayList)de.Value;
                }
                u.Firstname = (String)values[0];
                u.Lastname  = (String)values[1];
                u.Email     = (String)values[2];
                u.Campus    = (String)values[3]; 
                u.Building  = (String)values[4]; 
                u.RoomNo    = (String)values[5];
                u.Extension = (String)values[6];
                
                //Write to Working Data XML

                GetTaskModel gt = new GetTaskModel();
                gt.SetSelectedCustomer(searchResults);
            }
            
            return u;
        }
    }   
}
